<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单选题</title>
</head>
<body>

    <div class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'center',border:true">
           <table id="excel_export_20190624Header"></table>
        </div>
    </div>

    <div id="mm_20200531" class="easyui-menu" style="width:120px;display: none;">
        <div data-options="iconCls:'icon-add',id:'m-add-20200531'">新增</div>
        <div data-options="iconCls:'icon-edit',id:'m-update-20200531'">修改</div>
        <div data-options="id:'m-delete-20200531'">停用</div>
    </div>

    <div id="dialog_20200531_addOrUpdateOrMenu" style="padding:10px 30px;display: none;">
        <form id="from20200531" method="post" data-options="novalidate:true">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="updateID20200531-2" name="id" style="width:100%;" >
                <input class="easyui-textbox" name="title" style="width:100%" data-options="label:'题目:',required:true">
            </div>

            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="optionA" style="width:100%"  data-options="label:'选项-A:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="optionB" style="width:100%"  data-options="label:'选项-B:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="optionC" style="width:100%"  data-options="label:'选项-C:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="optionD" style="width:100%"  data-options="label:'选项-D:',required:true">
            </div>
            <div style="margin-bottom:20px">

                <select class="easyui-combobox" name="answer"  data-options="label:'正确选项:',panelHeight:'auto',required:true">
                    <option value="A" selected>A</option>
                    <option value="B">B</option>
                    <option value="C">C</option>
                    <option value="D">D</option>
                </select>
            </div>
        </form>
    </div>
    <div id="dialog_button_20200531" style="display: none;">
        <a id="submitForm2020close">放弃</a>
        <a id="submitForm2020">保存</a>
    </div>

<script>

    $(function () {
        $('#submitForm2020').linkbutton({
            iconCls: 'icon-ok',
            onClick: function (none) {
                submitForm2020()
            }
        });
        $('#submitForm2020close').linkbutton({
            onClick: function (none) {
                $('#dialog_20200531_addOrUpdateOrMenu').dialog('close');
            }
        });
    })

    //修改和保存
    function submitForm2020(){
        $('#from20200531').form('submit',{
            url:'./../radioDepot/mergeRadioDepot',
            iframe: false,
            onSubmit:function(param){
                console.log(param);
               // param.detail = ckf;
                let isValid = $(this).form('validate');
                return isValid;
            },
            success:function(json){
                let data = eval('(' + json + ')');
                if(data.code == 200){
                    new jBox('Notice', {
                        color: 'green',
                        autoClose: 2500,
                        content: '保存成功。',
                        showCountdown: true,
                        animation: 'slide'
                    });
                    reloadDatagrid20200605();
                }else{
                    new jBox('Notice', {
                        color: 'red',
                        autoClose: 2500,
                        content: '保存失败！',
                        showCountdown: true,
                        animation: 'slide'
                    });
                }
            }
        });
    }

    //按钮添加
    function hyzx_add_0615() {
        clearForm2();
      //  CKEDITOR.instances.editor1.setData('');
        $('#dialog_20200531_addOrUpdateOrMenu').dialog('open').dialog('center').dialog('setTitle','添加');
    }

    function loadLocal2(rowData){
        $('#from20200531').form('load',rowData);
    }

    function clearForm2(){
        $('#from20200531').form('clear');
    }
    //富文本框赋值
    function setDataCkeditor(msg){
       // CKEDITOR.instances.editor1.setData(msg);
    }
    $(function () {
        //实例化编辑器
        //Replace the <textarea id="editor1"> with a CKEditor
        //instance, using default configuration.
       // CKEDITOR.replace('editor1');

        $('#updateID20200531-2').next().hide(); //隐藏修改时候的id

        $('#dialog_20200531_addOrUpdateOrMenu').dialog({
            width: '50%',
           // height: '50%',
            closed: true,
            modal: true,
            buttons:'#dialog_button_20200531'
        });
        //鼠标右击菜单
        $('#mm_20200531').menu({
            onClick:function(item){
                clearForm2();
                let menuTitle = item.text;
                if(item.id == 'm-update-20200531'){
                    let rowData = $('#excel_export_20190624Header').datagrid('getSelected');
                    loadLocal2(rowData);
                    setDataCkeditor(rowData.detail);
                    $('#dialog_20200531_addOrUpdateOrMenu').dialog('open').dialog('center').dialog('setTitle',menuTitle);
                }
                if(item.id == 'm-add-20200531'){
                   // CKEDITOR.instances.editor1.setData('');
                    $('#dialog_20200531_addOrUpdateOrMenu').dialog('open').dialog('center').dialog('setTitle',menuTitle);
                }
                if(item.id == 'm-delete-20200531'){
                    $.messager.confirm('提示','确定要停用吗?停用后将不在抽题范围内！',function(r){
                        if (r){
                            let rowData = $('#excel_export_20190624Header').datagrid('getSelected');
                            deleteDatagrid20200605(rowData.id)
                        }
                    });
                }
            }
        });

        //行业咨询列表展示
        $('#excel_export_20190624Header').datagrid({
            url:'./../radioDepot/radioDepotPage',
            method: 'get',
            border: false,
            fit: true,
            fitColumns: true,
            scrollbarSize: 2, //滚动条宽度
            striped: true,
            rownumbers: true,
            pagination: true,
            singleSelect: true,
            sortName: 'id', //定义排序的列名
            sortOrder: 'desc',      //'asc' 或 'desc'。
            nowrap:false, //设置为 true，则把数据显示在一行里。设置为 true 可提高加载性能。
            toolbar:'#hyzx0613',
            columns:[[
                {field:'title',title:'题目',width:100},
                {field:'createTime',title:'创建时间',width:50},
                {field:'optionA',title:'A',width:50 },
                {field:'optionB',title:'B',width:50},
                {field:'optionC',title:'C',width:50},
                {field:'optionD',title:'D',width:50},
                {field:'answer',title:'答案',width:20},
                {field:'author',title:'添加人',width:50,hidden:true},
                {field:'state',title:'状态',width:50,
                    formatter: function(value,row,index){
                        if (value == 1){
                            return '<span class="easyui-dot easyui-status-processing"></span> 正常';
                        } else {
                            return '<span class="easyui-dot easyui-status-error"></span> 停用';
                        }
                    },
                    align:'left'
                }
                // {field:'cz',title:'操作',width:60,
                //     formatter: function(value,row,index){
                //         let cz = '<a href="#" class="loan_ct_view_button" data-options="iconCls:\'icon-edit\'" onclick="updateAndDelete0613(1,'+row.id+')">修改</a> ' +
                //             '<a href="#" class="loan_ct_view_button" data-options="iconCls:\'icon-remove\'" onclick="updateAndDelete0613(2,'+row.id+')">下架</a>'
                //         return cz;
                //     }
                // }
            ]],
            onLoadSuccess:function(data){
                $(".loan_ct_view_button").linkbutton({
                    plain:true
                })
            },
            onHeaderContextMenu: function(e, field){
                e.preventDefault();
                $(this).datagrid('columnMenu').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            },
            onRowContextMenu: function(e,index,row) {
                e.preventDefault();
                $(this).datagrid('unselectAll');
                let del = $('#m-delete-20200531')[0];
                let update = $('#m-update-20200531')[0];
                if(!row){
                    $('#mm_20200531').menu('hideItem', del).menu('hideItem', update);
                }else{
                    $('#mm_20200531').menu('showItem', del).menu('showItem', update);
                    $(this).datagrid('selectRow', index);
                }
                $('#mm_20200531').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            },
            onDblClickRow:function(index,row){
                $(this).datagrid('selectRow', index);
                loadLocal2(row);
                setDataCkeditor(row.detail);
                $('#dialog_20200531_addOrUpdateOrMenu').dialog('open').dialog('center').dialog('setTitle','修改');
            }
        });
    });

    function updateAndDelete0613(state,id) {
        alert(state+":"+id)
    }

    //设备发布中的信息-逻辑删除
    function deleteDatagrid20200605(id){
        $.ajax({
            type: "POST",
            url: "./../radioDepot/deleteRadioDepot",
            data: {id:id},
            success: function(json){
                if(json.code == 200){
                    new jBox('Notice', {
                        color: 'green',
                        autoClose: 2500,
                        content: ' 操作成功。',
                        showCountdown: true,
                        animation: 'slide'
                    });
                    reloadDatagrid20200605();
                }else{
                    new jBox('Notice', {
                        color: 'red',
                        autoClose: 2500,
                        content: '操作失败！',
                        showCountdown: true,
                        animation: 'slide'
                    });
                }
            }
        });
    }

    //刷新datagrid
    function reloadDatagrid20200605(){
        $('#dialog_20200531_addOrUpdateOrMenu').dialog('close');
        $('#excel_export_20190624Header').datagrid('reload');
    }
</script>
</body>
</html>